﻿Imports System.Text.RegularExpressions

Module Validaciones

    Public Function Validar(ByVal cadena As String, ByVal longitud As Integer, ByVal requerido As Boolean) As Boolean
        Dim salida As Boolean
        salida = False

        'Si es requerido no puede ser vacia
        If (requerido) Then
            If (cadena.Length > 0 And cadena.Length <= longitud) Then
                salida = True
            Else
                salida = False
            End If
            'puede ser vacia
        Else
            If (cadena.Length <= longitud) Then
                salida = True
            Else
                salida = False
            End If
        End If

        Return salida

    End Function

    Public Function ValidarDNI(ByVal dni As String) As Boolean
        Dim salida As Boolean
        salida = False

        If (dni.Length > 0 And dni.Length <= 9) Then
            salida = True
        End If

        Return salida

    End Function

    Public Function ValidarTlf(ByVal tlf As String) As Boolean
        Dim salida As Boolean
        salida = False

        If (tlf.Length > 0 And tlf.Length <= 9) Then
            salida = True
        End If

        Return salida
    End Function

    Public Function ValidarEmail(ByVal email As String) As Boolean
        Return Regex.IsMatch(email, "^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")
    End Function

    Public Function ValidarFacebook(ByVal facebook As String) As Boolean
        Dim salida As Boolean
        salida = False

        Return salida
    End Function

    Public Function ValidarTwitter(ByVal twitter As String) As Boolean
        Dim salida As Boolean
        salida = False

        Return salida
    End Function

End Module
